package com.zuihai.app.mvp.model.entity;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import com.zuihai.app.mvp.model.api.Api;
import com.zuihai.app.mvp.model.entity.mainhome.KPLogoBean;

import java.io.Serializable;
import java.util.List;

/**
 * 如果你服务器返回的数据固定为这种方式(字段名可根据服务器更改)
 * 替换范型即可重用BaseJson
 * Created by jess on 26/09/2016 15:19
 * Contact with jess.yan.effort@gmail.com
 */

public class BaseJson<T> implements Serializable {

    @SerializedName("code")
    @Expose
    public String code;
    @SerializedName("msg")
    @Expose
    public String msg;
    @SerializedName("data")
    @Expose
    public Result<T> data;
    @SerializedName("detailAd")
    @Expose
    public KPLogoBean detailAd;

    @Override
    public String toString() {
        return "BaseJson{" +
                "code='" + code + '\'' +
                ", msg='" + msg + '\'' +
                ", date=" + data +
                '}';
    }

    /**
     * 请求是否成功
     *
     * @return
     */
    public boolean isSuccess() {
        if (code.equals(Api.RequestSuccess)) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 请求是否删除
     *
     * @return
     */
    public boolean isDelete() {
        if (code.equals(Api.RequestUserNoexist)) {
            return true;
        } else {
            return false;
        }
    }

    public static class Result<T>{
        @SerializedName("result")
        @Expose
        public List<T> result = null;
    }

    public KPLogoBean getDetailAd() {
        return detailAd;
    }

    public void setDetailAd(KPLogoBean detailAd) {
        this.detailAd = detailAd;
    }
}
